Part Number Hot Search : 
SB1ST4 00BB7 101M1 SI4368DY TB30N0 BUZ900P MT10NF SCDAR6
Product Description
Full Text Search
 

To Download AN1216 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  september 2013 docid007016 rev 2 1/11 AN1216 application note implementing a periodic alarm with timekeeper ? and serial real-time clocks (rtcs) introduction the timekeeper ? and serial real-time clock (rtc) devices provide an alarm which can be set either for a given time and day, or to repeat at a certain day in every month, or at a certain hour in every day, or at a certain minute of every hour, or at a certain second of every minute. with this functionality already provided in the hardware, the software to implement an alarm of any given period is greatly simplified, as described in this document. although specifically tailored for the m48t37v/y device, applications can be easily adapted to use any of st?s other timekeeper or serial rtc devices that have the alarm feature. some modifications in the mcu memory mapping (the timekeeper or rtc address space) and in the mcu register mapping (such as the pointer to register address) would need to be made. table 1. timekeeper ? and serial rtc devices with alarm timekeeper m48t37v/y, m48t201v/y serial rtc m41t62, m41t63, m41t64, m41t65, m41t66, m41t80, m41t81, m41t81s, m41t82, m41t83, m41t93, m41t94, m41st85w, m41st87w www.st.com
AN1216 2/11 docid007016 rev 2 timekeeper ? configuration the timekeeper register mapping is shown in table 2 . this is divided in two parts: the clock registers and the alarm registers. clock registers the clock registers can be configured in the c language computer program as follows: *timekeeper_cal |= 0x80 *timekeeper_sec= 00 //user clock setting : seconds parameter *timekeeper_min= 00 //user clock setting : minutes parameter *timekeeper_hour= 00 //user clock setting : hours parameter *timekeeper_cal&= 0x7f the process for starting the clock and making the calibration adjustments are described in the m48t37v/y datasheet, and in application notes an925 and an934. alarm registers for timekeeper devices it is necessary to set the write bit, w, at the top of the control register (at address offset 7ff8h) before proceeding to any clock modification. modifications table 2. typical timekeeper ? (m48t37v/y) register map address data function range (in bcd format) d7 d6 d5 d4 d3 d2 d1 d0 7fffh 10 years year year 00-99 7ffeh 0 0 0 10m month month 01-12 7ffdh 0 0 10 date date date 01-31 7ffch 0 ft 0 0 0 day day 01-7 7ffbh 0 0 10 hours hours hour 00-23 7ffah 0 10 minutes 10 minutes minute 00-59 7ff9h st 10 seconds seconds second 00-59 7ff8h w r s calibration control 7ff7h wds bmb4 bmb3 bmb2 bmb1 bmb0 rb1 rb0 watchdog 7ff6h afe 0 abe 0 0 0 0 0 interrupt 7ff5h rpt4 0 al 10 date alarm date a date 01-31 7ff4h rpt3 0 al 10 hour alarm hour a hour 00-23 7ff3h rpt2 alarm 10 minutes alarm minutes a minute 00-59 7ff2h rpt1 alarm 10 seconds alarm seconds a second 00-59 7ff1h 1000 years 100 years century 00-99 7ff0h wdf af z bl z z z z flags
docid007016 rev 2 3/11 AN1216 11 to the alarm registers, though, can be made at any time, with no prior changes to the control register being necessary. the program listing, at the end of this document, contains statements to perform the following functions: 1. the stop bit (st, bit 7 of the register at offset 7ff9h) has to be reset to start the timekeeper oscillator *timekeeper_sec &= 0x7f; // reset bit d7 using a mask 0x7f 2. the alarm flag enable (afe) bit (bit 7 of the register at offset 7ff6h) is set, thereby allowing the irq pin (pin 40) to output the interrupt signal (active low). *tkper_al_it |= 0x80; // set bit d7 using a mask 0x80 3. the flag register (at offset 7ff0h) must be read at the beginning of the alarm updating routine. if not, the af flag will never be released, and the timekeeper will continuously output an interrupt to the mcu, and the system will become unresponsive. software configuration the program is listed in alarm update management . to understand its operation, it is important to distinguish between the three pointer variables, pointing to physical addresses in the hardware: *tkper_al_hour, *tkper_al_min, *tkper_al_sec and the three integer variables, used as work-space by the software: alarm_hour, alarm_minute, alarm_second the first three variables are pointers to the physical address of the values that are stored in the device. the three software variables are used to hold the user?s data (they specify the period of the alarm in hours, minutes and seconds). this is not the same information as is stored in the timekeeper registers, as pointed to by the pointer variables, but is used in their calculation. the program does make use of the four repeat bits (rpt4, rpt3, rpt2 and rpt1) that are physically located in the timekeeper device. these should all be set, except for those corresponding to fields that contain significant data. for instance, to set an alarm that repeats every 3 minutes and 45 seconds, the alarm_minutes and alarm_seconds variables would be loaded with these two values. then appropriate values would be calculated for loading in the ?alarm minutes? and ?alarm seconds? fields of the alarm registers (at addresses 7ff3h and 7ff2h, *tkper_al_min and *tkper_al_sec, respectively), and their repeat bits (rpt2 and rpt1, respectively) would be reset to ?0?. meanwhile, the alarm_hour variable, and the ?alarm date? and ?alarm hour? fields of the alarm registers (at addresses 7ff5h and 7ff4h, *tkper_al_date and *tkper_al_hour, respectively) would be treated as ?don?t care?, as indicated by their repeat bits (rpt4 and rpt3, respectively) being set. this is summarized in table 3 , with the three local integer variables, alarm_second, alarm_minute and alarm_hour, used to represent the period.
AN1216 4/11 docid007016 rev 2 for example, to set a period of 1 hour 49 minutes 35 seconds, the procedure is as follows: rpt4 = 1 rpt3 = rpt2 = rpt1 = 0 alarm_second = 0x35 alarm_minute = 0x49 alarm_hour = 0x01 or, to set a period of 49 minutes 35 seconds, the procedure is as follows: rpt4 = rpt3 = 1 rpt2 = rpt1 = 0 alarm_second = 0x35 alarm_minute = 0x49 alarm_hour = don?t care software implementation timekeeper ? data format timekeeper data is held as bcd (binary coded decimal). this is handled in the c programming language using the ?unsigned char? data type. this can be converted within the c program to other data types, such as ?integer?, for numeric processing. two functions are provided in the program at the end of this document for making this conversion. ? char_to_int: to take a bcd parameter, and to return the equivalent integer value ? int_to_char: to take an integer parameter, and to return the equivalent bcd value. the valid ranges for the alarm fields are summarized in table 4 . table 3. bit setting to control the period of the repeated alarm rpt4 rpt3 rpt2 rpt1 periodic alarm activated every 11111 second 1 1 1 0 alarm_second seconds (less than 1 minute) 1 1 0 0 alarm_minute minutes alarm_second seconds (less than 1 hour) 1 0 0 0 alarm_hour hours alarm_minute minutes alarm_second seconds (less than 1 day) table 4. timekeeper ? data format data c language type int (integer) decimal char (character) hexadecimal char (character) bcd alarm second 0-59 00-3b 0-59
docid007016 rev 2 5/11 AN1216 11 alarm update management when the alarm signal is generated by the timekeeper ? device, it is communicated to the mcu. the mcu can monitor for this event either by polling, or by using interrupts. there are two variants of each method: ? polling ? read the flag register and check the af bit (bit 6 of the register at offset 7ff0h) ? output the alarm signal on the timekeeper ? irq pin (pin 40), and read it on the mcu i/o port ? interrupts ? give priority to processing the alarm interrupt ? the alarm signal is used to cause a wake-up event the last option is ideally suited when power consumption is the critical issue. for instance, when measuring, processing and storing some metering data every three minutes, the mcu can stay in its standby state for 95% of the time, and only run at full speed, with high power consumption, during the other 5% of the time. the other interrupt option is ideally suited when service time is the critical issue. the mcu will be interrupted from whatever processing it was currently engaged in, to service the alarm event. this can be integrated into a hierarchy of prioritized interrupts. the two polling options are equally suited when the mcu needs to run at full speed, and full power, all of the time, executing important background work, only responding to the alarm event when it has nothing else to do. in polling method, the mcu is always running full speed and full power consumption. in this case, the application power consumption is not a key issue and/or the process to be executed due to an alarm which has no priority. the alarm check and update is served as every other application routine. the timekeeper irq pin (pin 40) is an active-low signal. in the following program, a routine ?update_next_alarm? is provided to take care of the periodic update of the alarm parameters. the program has been written in ansi c, and has been compiled and tested with an m68hc11 series mcu. /* timekeeper ; m48t37v/y periodic alarm source code : */ /* version: 1.01 */ /*********************************************************************************/ /* copyright (c) 1999 stmicroelectronics. */ /* */ /* this program is provided ?as is? without warranty of any kind, either */ /* expressed or implied, including but not limited to, the implied warranty */ /* of merchantability and fitness for a particular purpose. the entire risk */ alarm minute 0-59 00-3b 0-59 alarm hour 0-12 00-0b 0-12 table 4. timekeeper ? data format data c language type int (integer) decimal char (character) hexadecimal char (character) bcd
AN1216 6/11 docid007016 rev 2 /* as to the quality and performance of the program is with you. should the */ /* program prove defective, you assume the cost of all necessary servicing, */ /* repair or correction. */ /*********************************************************************************/ /****************************************************************/ /* */ /* this program controls the timekeeper alarm hardware so */ /* as to provide the functionality of a periodic alarm. */ /* */ /****************************************************************/ #include // this was developed on hc11 platform #include // m88 flash+psd register map extern volatile unsigned char dip_sw; /*********************************************************************/ /* timekeeper memory map */ /* depend on your system and your timekeeper. */ /* the device is m48t37v/y series, 32kx8 non volatile sram, 16 clock */ /* alarm registers in address 7ff8h to 7fffh */ /* in this example, the timekeeper was mapped from 2000h to 9fffh */ /*********************************************************************/ /* #ifndef _mem_map_h #define _mem_map_h #define ext_ram_base (unsigned int) 0x2000 #define timekeeper_hour (unsigned char *) 0x9ffb #define timekeeper_min (unsigned char *) 0x9ffa #define timekeeper_sec (unsigned char *) 0x9ff9 #define timekeeper_cal (unsigned char *) 0x9ff8 #define tkper_al_it (unsigned char *) 0x9ff6 #define tkper_al_date (unsigned char *) 0x9ff5 #define tkper_al_hour (unsigned char *) 0x9ff4 #define tkper_al_min (unsigned char *) 0x9ff3 #define tkper_al_sec (unsigned char *) 0x9ff2 #define tkper_flag (unsigned char *) 0x9ff0 #endif */ /**************************************************************************/ /* function char_to_int */ /* description : this function convert the timekeeper data*/ /* (in bcd format) to an integer. */ /* input : char byte */ /* output : integer */ /* example : octet = 0x33 (51 in integer) */ /* char_to_int = 33 (0x21 in hexa) */ /**************************************************************************/ int char_to_int(unsigned char octet) { int buffer; buffer = (int)(octet); if (octet <= 0x09) return(buffer); if ((octet >= 0x10) & (octet <= 0x19)) return (buffer-6); if ((octet >= 0x20) & (octet <= 0x29)) return (buffer-12); if ((octet >= 0x30) & (octet <= 0x39)) return (buffer-18);
docid007016 rev 2 7/11 AN1216 11 if ((octet >= 0x40) & (octet <= 0x49)) return (buffer-24); if ((octet >= 0x50) & (octet <= 0x59)) return (buffer-30); } /**************************************************************************/ /* function int_to_char */ /* description : this function convert an integer data */ /* to bcd timekeeper format (unsigned char) */ /* input : int integ */ /* output : unsigned char */ /* example : integ = 33 (0x21 in hexa) */ /* int_to_char = 0x33 (51 in integer) */ /**************************************************************************/ unsigned char int_to_char(int integ) { char buffer; buffer = (unsigned char)(integ); if (integ <= 9) return(buffer); if ((integ >= 10) & (integ <= 19)) return (buffer+6); if ((integ >= 20) & (integ <= 29)) return (buffer+0x0c); if ((integ >= 30) & (integ <= 39)) return (buffer+0x12); if ((integ >= 40) & (integ <= 49)) return (buffer+0x18); if ((integ >= 50) & (integ <= 59)) return (buffer+0x1e); } /*************************************************************************/ /* void update_next_alarm */ /* description : after alarm interupt, it will : */ /* - reset the timekeeper it flag */ /* - read the actual time in the clock register */ /* - calculate the next alarm time */ /* - update the alarm register */ /* to prepare for the next alarm */ /* input : alarm period (al_hour, al_minute, al_second) */ /* output : nothing */ /*************************************************************************/ void update_next_alarm(int al_hour,int al_minute,int al_second) { // time carry, going to be used for hour, minute and second // calculation process. unsigned char time_flag = 0; // intermediate storage for alarm data. int buffsec; int buffmin; int buffhour; // temporary storage unsigned char buffchar; // touch the flag register to reset timekeeper af flag (interupt) buffchar = *tkper_flag; /*****************************************************************/ /* this is to update the alarm second register. */ /* it will test if rpt1 is set. if not then it adds ?al_second? */ /* to second alarm register. it takes care of the minute carry. */ /*****************************************************************/ if (!(*tkper_al_sec & 0x80)) // if !rpt1 { // update register with carry buffsec = char_to_int(*timekeeper_sec) + al_second; if (buffsec > 59) // if >59 { // then restore 60sec format
AN1216 8/11 docid007016 rev 2 *tkper_al_sec = int_to_char(buffsec-60); time_flag = 1; } else *tkper_al_sec = int_to_char(buffsec); // normal case } /*****************************************************************/ /* this is to update the alarm minute register. */ /* it will test if rpt2 is set. if not then it adds ?al_minute? */ /* to alarm minute register. it takes care of the hour carry. */ /*****************************************************************/ if (!(*tkper_al_min & 0x80)) // if !rpt2 { // update register with carry buffmin = char_to_int(*timekeeper_min) + al_minute + time_flag; if (buffmin > 59) // if >59 { // then restore 60 min format *tkper_al_min = int_to_char(buffmin-60); time_flag = 1; } else { *tkper_al_min = int_to_char(buffmin); // normal case time_flag = 0; } } /*****************************************************************/ /* this is to update the alarm hour register. */ /* it will test if rpt2 is set. if not then it adds ?al_hour? to */ /* alarm hour register */ /*****************************************************************/ if (!(*tkper_al_hour & 80)) { buffhour = char_to_int(*timekeeper_hour) + al_hour + time_flag; if (buffhour > 23) *tkper_al_hour = int_to_char(buffhour-24); else *tkper_al_hour = int_to_char(buffhour); } } main(void) { int alarm_second; // relative alarm variable int alarm_minute; int alarm_hour; /*****************************************************************/ /* timekeeper alarm configuration example. */ /*****************************************************************/ // memory-mapped unsigned char pointers *tkper_al_hour &= 0x7f; // to the external hardware registers *tkper_al_min &= 0x7f; // to set a one-off alarm *tkper_al_sec &= 0x7f; // for a fixed time today. // local memory integer variables
docid007016 rev 2 9/11 AN1216 11 alarm_hour = 1; // to hold the repetition period alarm_minute = 49; // for an alarm (& an interrupt on pin 26) alarm_second = 35; // every 1hr 49min 35sec (for example). // start the timekeeper oscillator. *timekeeper_sec &= 0x7f; // rpt4 set *tkper_al_day |= 0x80; // enable irq request on pin40 (m48t37v/y) *tkper_al_it |= 0x80; while (1) { /*******************************************************************/ /* read_the_port is a read of mcu i/o to detect an alarm interrupt */ /* lcd_min_display is a lcd software driver used for routine debug */ /* those library were developed for flash+psd development board. */ /*******************************************************************/ read_the_ports(); lcd_min_display(0,3,*timekeeper_hour); // display current time lcd_min_display(0,7,*timekeeper_min); lcd_min_display(0,13,*timekeeper_sec); if (dip_sw==0x0e) // dip_sw is updated by read_the_port // if detect alarm interrupt from timekeeper { update_next_alarm(alarm_hour,alarm_minute,alarm_second); lcd_min_display(1,3,*tkper_al_hour); // display next alarm time lcd_min_display(1,7,*tkper_al_min); lcd_min_display(1,13,*tkper_al_sec); } } }
revision history AN1216 10/11 docid007016 rev 2 revision history table 5. document revision history date revision changes feb-2000 1 initial release. 03-sep-2013 2 updated title of document removed references to obsolete products added table 1: timekeeper ? and serial rtc devices with alarm updated table 2 and text throughout the document to reflect the memory map and address of the m48t37v/y device
docid007016 rev 2 11/11 AN1216 11 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. a ll st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a particular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not authorized for use in weapons. nor are st products designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems with product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ?automotive, a utomotive safety or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2013 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN1216

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X